package com.flexycore.iphone.view;


import com.flexycore.iphone.controller.ActionSheetDelegate;
import com.flexycore.iphone.coregraphics.CGRect;
import com.flexycore.iphone.uikit.UIActionSheet;
import com.flexycore.iphone.uikit.UIActionSheetStyle;
import com.flexycore.iphone.uikit.UIButton;
import com.flexycore.iphone.uikit.UIColor;
import com.flexycore.iphone.uikit.UIControlEvents;
import com.flexycore.iphone.uikit.UIImage;
import com.flexycore.iphone.uikit.UINavigationController;
import com.flexycore.iphone.uikit.UIView;


/**
 * 
 * @author matthieu nicolazo
 *
 */
public class MainView extends UIView {
	/**
	 * Fields
	 */
	private UIActionSheet actionSheet;
	private UINavigationController nav;
	
	/**
	 * 
	 * @param n		UINavigationController containing this view.
	 */
	public MainView(UINavigationController n){
		super();
		init();
		nav = n;
		
		/*
		 * ActionSheet
		 */
		actionSheet = new UIActionSheet();
		actionSheet.init();
		actionSheet.setActionSheetStyle(UIActionSheetStyle.UIActionSheetStyleBlackOpaque);
		actionSheet.setDelegate(new ActionSheetDelegate(this));
		actionSheet.setTitle("How many items do you want to display ?");
		actionSheet.addButtonWithTitle("Cancel");
		actionSheet.setCancelButtonIndex(0);
		actionSheet.dismissWithClickedButtonIndexAnimated(0, true);
		actionSheet.addButtonWithTitle("One item");
		actionSheet.addButtonWithTitle("Two items");
		actionSheet.addButtonWithTitle("Three items");
		actionSheet.addButtonWithTitle("Four items");
		
		/*
		 * Button
		 * Being used to open the UIActionSheet.
		 */
		UIButton button = new UIButton(){
			//@Override
			public void controlEvent() {
				// Display the UIActionSheet
				actionSheet.showInView(this.superview());
			}
		};
		button.initWithFrame(CGRect.CGRectMake(85, 30, 150, 31));
		button.setBackgroundImageForState(UIImage.imageNamed("buttonBackground.tiff"), 0);
		button.setTitleForState("Create view", 0);
		button.setTitleColorForState(UIColor.blackColor(), 0);
		button.addTargetActionForControlEvents(UIControlEvents.UIControlEventTouchUpInside);
		addSubview(button);
	}
	
	/**
	 * 
	 * @return	nav		Current UINavigationController.
	 */
	public UINavigationController getNavigationController(){
		return nav;
	}

}
